Skip to content

Fix new/free mismatch when differentiating delegating constructors. - #1934

Merged
vgvassilev merged 1 commit into
masterfrom
valgrind-ctors
Jul 30, 2026
Merged

Fix new/free mismatch when differentiating delegating constructors.#1934
vgvassilev merged 1 commit into
masterfrom
valgrind-ctors

Conversation

@vgvassilev

Copy link
Copy Markdown
Owner

For a delegating constructor initializer, DifferentiateCtorInit replaced _this's initializer -- set by BuildThisExpr to malloc and paired with free(_this) -- with an allocating new ClassTy(args), so the new-ed pointer was then handed to free(). Valgrind reports the mismatched deallocation in Gradient/Constructors.C.

Emit a placement new into the malloc'd _this instead, as the base-initializer path already does, keeping allocation and deallocation malloc/free.

For a delegating constructor initializer, DifferentiateCtorInit replaced
`_this`'s initializer -- set by BuildThisExpr to malloc and paired with
free(_this) -- with an allocating `new ClassTy(args)`, so the new-ed
pointer was then handed to free(). Valgrind reports the mismatched
deallocation in Gradient/Constructors.C.

Emit a placement new into the malloc'd `_this` instead, as the
base-initializer path already does, keeping allocation and deallocation
malloc/free.
@github-actions

Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@vgvassilev
vgvassilev merged commit 1517207 into master Jul 30, 2026
40 checks passed
@vgvassilev
vgvassilev deleted the valgrind-ctors branch July 30, 2026 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant